<template>
  <view>
    <div class="pie-chart" :style="{ '--percentage': percentage }">
      <span>{{ percentage }}%</span>
    </div>
  </view>
</template>

<script>
export default {
  name: "version-canvas",
  props: {
    fatherMsg: {
      type: Number,
      default: 40,
    },
  },
  data() {
    return {
      percentage: this.fatherMsg, // 初始化时同步父组件的值
    };
  },
  watch: {
    fatherMsg(newVal) {
      this.percentage = newVal; // 当父组件值变化时更新
    },
  },
};
</script>

<style lang="scss" scoped>
.pie-chart {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  background: conic-gradient(rgba(255, 255, 255, 1) 0% calc(var(--percentage) * 1%), rgba(110, 88, 170, 1) calc(var(--percentage) * 1%) 100%);
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  --percentage: 40;
}

.pie-chart::after {
  content: '';
  width: 60px;
  height: 60px;
  background: white;
  border-radius: 50%;
  position: absolute;
  z-index: 1;
}

.pie-chart span {
  position: relative;
  font-size: 35rpx;
  font-weight: bold;
  color: #000000;
  z-index: 2;
}
</style>
